import { NextResponse } from 'next/server';
import pool from '@/utils/db';

export async function GET() {
  try {
    // 尝试连接数据库并执行简单查询
    const [result] = await pool.query('SELECT COUNT(*) as count FROM users');
    
    // 返回成功响应
    return NextResponse.json({
      status: 'success',
      message: '数据库连接成功',
      data: result,
      timestamp: new Date().toISOString()
    });
  } catch (error) {
    console.error('数据库连接测试失败:', error);
    
    // 返回错误响应
    return NextResponse.json({
      status: 'error',
      message: '数据库连接失败',
      error: error instanceof Error ? error.message : '未知错误',
      timestamp: new Date().toISOString()
    }, { status: 500 });
  }
}
